package com.orangelife.mobile.washcar.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.curry.android.util.StringUtil;
import com.curry.orangelife.mobile.R;
import com.orangelife.mobile.common.activity.OrangeLifeBaseActivity;
import com.orangelife.mobile.common.view.ConfirmDialog;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 备注
 * Created by ${shz} on 2016/2/22.
 */
public class WashCarRemarkActivity extends OrangeLifeBaseActivity {
    @Bind(R.id.ib_title_left)
    LinearLayout ibTitleLeft;
    @Bind(R.id.tv_title)
    TextView tvTitle;
    @Bind(R.id.tv_one)
    TextView tvOne;
    @Bind(R.id.ll_addressManage)
    LinearLayout llAddressManage;
    @Bind(R.id.rl_title)
    RelativeLayout rlTitle;
    @Bind(R.id.etNote)
    EditText etNote;
    String remark;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wash_car_remark);
        ButterKnife.bind(this);
        initView();
    }

    private void initView() {
        remark = getIntent().getStringExtra("remark");
        if (!StringUtil.isBlank(remark)) {
            etNote.setText(remark);
            etNote.setSelection(remark.length());
        }
        tvTitle.setText("备注");
        tvOne.setText("确定");
        tvOne.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                Bundle bundle = new Bundle();
                bundle.putString("remark", String.valueOf(etNote.getText()));
                intent.putExtras(bundle);
                setResult(3, intent);
                closeKeybord();
                finish();
            }
        });
    }
    private void closeKeybord(){
        if(getCurrentFocus()!=null)
        {
            ((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE))
                    .hideSoftInputFromWindow(getCurrentFocus()
                                    .getWindowToken(),
                            InputMethodManager.HIDE_NOT_ALWAYS);
        }
    }
    public void onBackClick(View v) {
        final ConfirmDialog dialog = new ConfirmDialog(this, "提示", "退出所写内容将被清空，确定要退出吗？", "确定", "取消");
        dialog.show();
        dialog.setClicklistener(new ConfirmDialog.ClickListenerInterface() {
            @Override
            public void doLeft() {
                dialog.dismiss();
                closeKeybord();
                finish();
            }

            @Override
            public void doRight() {
                dialog.dismiss();
            }
        });

    }

}
